import random

import requests
from util.proxy import get_proxies_poll,get_proxy

urls = [f"https://httpbin.org/get?age={i}" for i in range(100)]
proxies_poll = get_proxies_poll(2)

while len(urls):
    url = urls.pop()
    proxy = random.choice(proxies_poll)
    try:
        response = requests.get(url, proxies=proxy)
        print(response.json())

    except requests.exceptions.ProxyError as e:
        print("代理异常", e)
        proxies_poll.remove(proxy)
        proxies_poll.append(get_proxy())
        urls.append(url)

    except Exception as e:
        print("其他异常", e)
        urls.append(url)

